package com.crunch.physics;

import com.crunch.math.Ray2f;
import com.crunch.math.Vector2f;

/**
 * Describes a ray to be cast in the scene.
 */
public class PhysicsRaycast {
	public static class Result {
		public enum IntersectionType {
			NONE,
			SCENE,
			DYNAMIC_ENTITY,
			MOVABLE_ENTITY,
			PROXIMITY_ZONE
		}

		// type of intersection
		public IntersectionType intersectionType;

		// time of intersection
		public float t;

		// point of intersection
		public Vector2f point;

		// normal of intersection
		public Vector2f normal;

		// intersection object, depending on intersectionType:
		// NONE: null
		// SCENE: null
		// DYNAMIC_ENTITY: DynamicPhysicsEntity
		// MOVABLE_ENTITY: MovablePhysicsEntity
		// PROXIMITY_ZONE: PhysicsProximityZone
		public Object intersectionObject;

		// intersection index, depending on intersectionType:
		// NONE: -1
		// SCENE: index of static collider
		// DYNAMIC_ENTITY: -1
		// MOVABLE_ENTITY: index of collider within shape
		// PROXIMITY_ZONE: -1
		public int intersectionIndex;
	}

	// used to handle intersections
	public interface IntersectionEventHandler {
		// return whether the raycast should continue
		// if true is returned, onIntersect may continue to be called
		// if false is returned, this call is the last one
		public boolean onIntersect(Result result);
	}

	// the ray to cast - the magnitude of direction represents the maximum cast distance
	public Ray2f ray;

	// radius of the ray, or 0 to cast a point
	public float radius;

	// whether to test each object type
	public boolean testStaticColliders;
	public boolean testDynamicEntities;
	public boolean testMovableEntities;
	public boolean testProximityZones;

	// category mask for dynamic entities
	public int categoryMask;

	// handler for intersections
	public IntersectionEventHandler eventHandler;
}
